package com.rsc.learningbar.vo;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

public class Plan implements Delayed {
    /* 触发时间*/
    private long time;
    public StudentPlanVo planVo;

    public Plan(StudentPlanVo planVo, long time, TimeUnit unit) {
        this.planVo = planVo;
        this.time = System.currentTimeMillis() + (time > 0 ? unit.toMillis(time) : 0);
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return time - System.currentTimeMillis();
    }

    @Override
    public int compareTo(Delayed o) {
        Plan item = (Plan) o;
        long diff = this.time - item.time;
        if (diff <= 0) {// 改成>=会造成问题
            return -1;
        } else {
            return 1;
        }
    }

    @Override
    public boolean equals(Object obj) {
        Plan plan = (Plan) obj;
        return planVo.getId().equals(plan.planVo.getId());
    }
}
